import sqlite3

import setting
from database.IDataBase import IDataBase
from database.bean import ParamBean


class SqliteDataBase(IDataBase):

    def __init__(self):
        self.conn = sqlite3.connect(setting.SQLITE_DATABASE.get('path'))
        self.cur = self.conn.cursor()
        self.sql = None

    def sql_select(self, sql) -> list:
        self.sql = sql
        return list(self.cur.execute(sql))

    def sql_execute(self, sql):
        self.sql = sql
        self.cur.execute(sql)
        self.commit()

    def get_field_list(self) -> list:
        desc: tuple = self.cur.description
        fields = list(x[0] for x in desc)
        return fields

    def close(self):
        self.cur.close()
        self.conn.close()

    def commit(self):
        self.conn.commit()
